package com.hn.sanya.demo.test;


import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

/**
 * 功能描述:
 * @param:
 * @return:
 * @auther: lxh
 * @date: 2019/2/15
 */
public class reptile {

    /**
     * 单例工具类
     */
    private reptile() {
    }
    /**
     * 获取万年历信息
     * @return
     */
    public static void data(){



        String url="https://pub.alimama.com/myunion.htm?spm=a219t.7900221/10.1998910419.dab027959.7d1e75a5CPEEAW#!/promo/self/shop_detail?userNumberId=2939316415";
        UserServer.getUser(url);

        /*String url="http://tools.2345.com/rili.htm";
        Almanac almanac=analyzeHTMLByString(html);*/


    }

    /*
     * 使用jsoup解析网页信息
     */
    private static Almanac analyzeHTMLByString(String html){
        String solarDate,lunarDate,chineseAra,should,avoid=" ";
        Document document = Jsoup.parse(html);
        //公历时间
        solarDate=getSolarDate();
        //农历时间
        Element eLunarDate=document.getElementById("info_nong");
        lunarDate=eLunarDate.child(0).html().substring(1,3)+eLunarDate.html().substring(11);
        //天干地支纪年法
        Element eChineseAra=document.getElementById("info_chang");
        chineseAra=eChineseAra.text().toString();
        //宜
        should=getSuggestion(document,"yi");
        //忌
        avoid=getSuggestion(document,"ji");
        Almanac almanac=new Almanac(solarDate,lunarDate,chineseAra,should,avoid);
        return almanac;
    }
    /*
     * 获取忌/宜
     */
    private static String getSuggestion(Document doc,String id){
        Element element=doc.getElementById(id);
        Elements elements=element.getElementsByTag("a");
        StringBuffer sb=new StringBuffer();
        for (Element e : elements) {
            sb.append(e.text()+" ");
        }
        return sb.toString();
    }

    /*
     * 获取公历时间,用yyyy年MM月dd日 EEEE格式表示。
     * @return yyyy年MM月dd日 EEEE
     */
    private static String getSolarDate() {
        Calendar calendar = Calendar.getInstance();
        Date solarDate = calendar.getTime();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy年MM月dd日 EEEE");
        return formatter.format(solarDate);
    }

    public static void main(String[] args) {
        reptile.data();
    }

}